package com.aipartner.controller;

import com.aipartner.common.Result;
import com.aipartner.dto.AssistantFunctionResponse;
import com.aipartner.service.AssistantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Professional Assistant Controller
 * 
 * @author AI Partner Team
 * @since 2024-01-20
 */
@Api(tags = "Professional Assistant")
@RestController
@RequestMapping("/api/assistant")
@RequiredArgsConstructor
@Slf4j
public class AssistantController {
    
    private final AssistantService assistantService;
    
    @ApiOperation("Get All Categories and Functions")
    @GetMapping("/categories")
    public Result<List<Map<String, Object>>> getAllCategories() {
        List<Map<String, Object>> categories = assistantService.getAllCategories();
        return Result.success(categories, "Categories loaded successfully");
    }
    
    @ApiOperation("Get Functions by Category")
    @GetMapping("/categories/{categoryId}")
    public Result<List<AssistantFunctionResponse>> getFunctionsByCategory(
            @ApiParam("Category ID") @PathVariable String categoryId) {
        
        List<AssistantFunctionResponse> functions = assistantService.getFunctionsByCategory(categoryId);
        return Result.success(functions, "Functions loaded successfully");
    }
    
    @ApiOperation("Get Function Details")
    @GetMapping("/functions/{functionId}")
    public Result<AssistantFunctionResponse> getFunctionDetails(
            @ApiParam("Function ID") @PathVariable String functionId) {
        
        AssistantFunctionResponse function = assistantService.getFunctionDetails(functionId);
        if (function != null) {
            return Result.success(function, "Function details loaded successfully");
        } else {
            return Result.fail("Function not found");
        }
    }
    
    @ApiOperation("Search Functions")
    @GetMapping("/search")
    public Result<List<AssistantFunctionResponse>> searchFunctions(
            @ApiParam("Search keyword") @RequestParam String keyword) {
        
        List<AssistantFunctionResponse> functions = assistantService.searchFunctions(keyword);
        return Result.success(functions, "Search completed successfully");
    }
    
    @ApiOperation("Get Hot Recommendations")
    @GetMapping("/hot")
    public Result<List<AssistantFunctionResponse>> getHotRecommendations() {
        List<AssistantFunctionResponse> functions = assistantService.getHotRecommendations();
        return Result.success(functions, "Hot recommendations loaded successfully");
    }
}